﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Crochet.Core.Policy
{
	public class DefaultExecutionPolicy : BaseExecutionPolicy
	{
		public DefaultExecutionPolicy()
			: this(null, null, null)
		{
		}

		public DefaultExecutionPolicy(IScheduler sRootScheduler, SchedulerDelegate sdSchedulerProcess, ExceptionHandlerDelegate ehdExceptionHandlerDelegate)
			: base(sRootScheduler, sdSchedulerProcess, ehdExceptionHandlerDelegate)
		{
		}

		public override void Execute(IScheduler sSourceScheduler)
		{
			try
			{
				sdSchedulerProcess(sSourceScheduler);
			}
			catch (Exception eException)
			{
				if (ehdExceptionHandlerDelegate != null)
				{
					ehdExceptionHandlerDelegate(eException);
				}
			}
		}

		public override IExecutionPolicy Clone(SchedulerDelegate sdSchedulerProcess, ExceptionHandlerDelegate ehdExceptionHandlerDelegate)
		{
			DefaultExecutionPolicy depNewPolicy = new DefaultExecutionPolicy(sRootScheduler, sdSchedulerProcess, ehdExceptionHandlerDelegate);

			return depNewPolicy;
		}
	}
}
